# encoding = utf-8
import time

from application.model.outside_temperature.connect_mysql_read_weather_data import connect_mysql_read_weather_data


def get_weather_timestamp_list(data):
    """
    获取时间戳列表
    :param data: 天气数据
    :return: 时间戳列表
    """
    # 采集时间
    times = data['uptime']  # TODO 数据类型
    # 数据转换
    times = list(times)
    # 数据排序
    times_sorted = sorted(times)
    # 开始时间，结束时间
    times_sorted_first = times_sorted[0]
    times_sorted_last = times_sorted[-1]
    # 打印时间
    print("+" * 60)
    print(f"可以测的供热季范围：{times_sorted_first}到{times_sorted_last}")
    print("+" * 60)
    # 时间列表:时间戳
    timestamp_list = []
    # 时间处理:循环
    # > for =============================================
    for _ in times:
        # 解析日期
        ans_time = time.strptime(str(_), "%Y-%m-%d %H:%M:%S")
        # print(ans_time)
        # 转换日期:时间戳
        time_stamp = float(time.mktime(ans_time))
        # print(time_stamp)
        # 存储日期
        timestamp_list.append(time_stamp)
        pass
    # < for =============================================
    return timestamp_list
    pass


if __name__ == '__main__':
    _area_code = "110106000000"
    _data = connect_mysql_read_weather_data(area_code=_area_code)
    get_weather_timestamp_list(data=_data)
    pass
